#include <iostream>  
using namespace std;

int find(int *f,int *v,int x){
//	cout<<(c==1?"x:":"y:")<<x<<endl;
	if(f[x] == x)
		return x;
	int t=f[x];
	f[x]=find(f,v,t);
	v[x]=(v[x]+v[t])%2;
	return f[x];
}


int main(){
	int n,m,ans=0;
	cin>>n>>m;
	int f[n],v[n];
	for(int i=0;i<n;i++)
		f[i]=i,v[i]=0;
//	for(int i=0;i<n;i++)
//		cout<<i<<":"<<f[i]<<"  "<<v[i]<<endl;
	for(int i=0;i<m;i++){
		char opt;
		int x,y;
   		cin>>opt>>x>>y;
		x--;
		y--;
//		cout<<"y = "<<y<<endl;
		if(opt == 'F'){
			int fx=find(f,v,x),fy=find(f,v,y);
   			if(fx != fy){
				f[fx] = fy;
				v[fx] = (v[x]+v[y])%2; 
			}
		}
		else{
			int fx=find(f,v,x),fy=find(f,v,y);
			if (fx != fy) {
				f[fx]=fy;
				v[fx]=(1+v[x]+v[y])%2;  
			}
		}
	}
	for(int i=0;i<n;i++){
		int nmax=0;
		int fx,fy;
		fx = find(f,v,i);
		for(int j=0;j<n;j++){
			fy = find(f,v,j);
			if(fx == fy  &&  (v[i]+v[j])%2 == 0)
				nmax++;
		}
		if(nmax > ans)
			ans = nmax;
	}
	cout<<ans;
	return 0;
}
